<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/22
 * Time: 17:53
 */

namespace Home\Controller;


class ShellController
{
    //超时自动收货
    public function time_out_delivery()
    {
        //查询已发货，但是还没收货的订单
        $res = M('order')->where(array('status'=>'0','is_deliver'=>1))->select();
        $now = time();
        $over_day = M('config')->where("conf_key = 'over_day' AND shop_id = %d" ,array(session("reception_shopid")))->getField("conf_value");
        foreach ($res as $key => $value){
            //超时7天自动收货604800
            $time_out = $value['deliver_time'] + (3600 * 24 * $over_day);
            if($now > $time_out){
                // 超时,改成收货
                M('order')->where(array('id'=>$value['id']))->setField('status',3);
                //并且更改agent销售额
                $all_chi = M('agent')->where( array('agent_id'=>$value['uid']) )->getField('all_achi');
                $new_all_chi = $value['price'] + $all_chi;
                M('agent')->where( array('agent_id'=>$value['uid']) )->save( array('all_achi'=>$new_all_chi) );
            }
        }
    }
}